package cn.edu.lingnan.translation.utils;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @ClassName MyMetaObjectHandler
 * @Author BAO
 * @Description 实体类创建时间、更新时间处理
 * @Date 2020/10/11 13:02
 * @Version 1.0
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    /**
     * @Description 插入填充字段
     * @Param [metaObject]
     * @Return void
     * @Author BAO
     * @Date 2020/10/11 13:09
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        // 填充字段
        this.setFieldValByName("createTime", new Date(), metaObject);
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }

    /**
     * @Description 更新填充字段
     * @Param [metaObject]
     * @Return void
     * @Author BAO
     * @Date 2020/10/11 13:09
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }
}
